package com.abvnet.project.water.project.controller;

import com.abvnet.framework.aspectj.lang.annotation.Log;
import com.abvnet.framework.aspectj.lang.enums.BusinessType;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.project.domain.ProjectFlowParam;
import com.abvnet.project.water.project.service.IProjectFlowParamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目流程处理单元参数操作处理
 * 
 * @author wolf
 * @date 2019-10-22
 */
@Controller
@RequestMapping("/project/projectFlowParam")
@Slf4j
public class ProjectFlowParamController extends BaseController {
    private String prefix = "project/projectInfo";

    @Autowired
    private IProjectFlowParamService projectFlowParamService;


    @GetMapping("/{projectId}")
    public String projectFLowParam(@PathVariable("projectId") Long projectId, ModelMap mmap)
    {
        ProjectFlowParam projectFlowParam = new ProjectFlowParam();
        projectFlowParam.setProjectId(projectId);
        mmap.put("projectFlowParam", projectFlowParam);
        return prefix + "/flowParam";
    }

    /**
     * 查询项目列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectFlowParam projectFlowParam) {
//        if (ShiroUtils.getSysUser().isAdmin()) {
//            projectFlowParam.setCreateBy(ShiroUtils.getLoginName());
//        }
        startPage();
        List<ProjectFlowParam> list = projectFlowParamService.selectProjectFlowParamByProjectId(projectFlowParam.getProjectId());
        return getDataTable(list);
    }

	/**
	 * 修改项目流程处理单元参数
	 */
    @GetMapping("/edit/{flowId}/{projectId}")
    public String edit(ProjectFlowParam projectFlowParam, ModelMap mmap) {
       mmap.put("projectFlowParam", projectFlowParamService.selectProjectFlowParam(projectFlowParam));
        return prefix + "/editFlowParam";
    }
	
	/**
	 * 修改项目流程处理单元参数
	 */
	@Log(title = "处理工艺流程参数", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProjectFlowParam projectFlowParam) {
        try {
            return toAjax(projectFlowParamService.updateProjectFlowParam(projectFlowParam));
        } catch (Exception e) {
            log.error("更新项目流程处理单元参数！", e);
            return error(e.getMessage());
        }
	}
}
